/** 
 *  @file
 *  @brief   工字形（I）梁截面属性使用解析公式计算类
 *  @author  lijiayang
 *  @date    2024.03.29
 *  @version v1.0
 *  @par Copyright(c):  ShenGong  Simulation corporation
 */

#include "ISectionFormulaCalculator.h"
#include "DataStructure/Common/Real.h"

using SG::DataStructure::Common::Real;
using SG::DataStructure::FEM::PBARLData;
using SG::DataStructure::FEM::PBARData;
using SG::FEMSolver::Element::ISectionFormulaCalculator;

void ISectionFormulaCalculator::Compute
(
const SG::DataStructure::FEM::PBARLData& section,
_OUT SG::DataStructure::FEM::PBARData&   property,
_OUT SG::Algebra::Point&                 centroid
) const
{
    Real a{section.m_dimension[1]};
    Real b{section.m_dimension[2]};
    Real h{section.m_dimension[0]};
    Real ta{section.m_dimension[4]};
    Real tb{section.m_dimension[5]};
    Real tw{section.m_dimension[3]};
    Real hw{h - (ta + tb)};
    Real hf{h - 0.5 * (ta + tb)};

    property.m_id  = section.m_id;
    property.m_mId = section.m_mId;
    property.m_A   = ta * a + hw * tw + b * tb;
    // Real yS = (tb * hf * b * b * b) / (tb * b * b * b + ta * a * a * a);
    // Real zS = 0.0;
    Real yC = (hw * tw * 0.5 * (hw + ta) + b * tb * hf) / property.m_A;
    // Real zC = 0.0;
    property.m_I1  = b * tb * tb * tb / 12.0 + a * ta * ta * ta / 12.0 + tw * hw * hw * hw / 12.0 + b * tb * (hf - yC) * (hf - yC) +
                     a * ta * yC * yC + tw * hw * (yC - 0.5 * (hw + ta)) * (yC - 0.5 * (hw + ta));
    property.m_I2  = tb * b * b * b / 12.0 + ta * a * a * a / 12.0 + hw * tw * tw * tw / 12.0;
    property.m_I12 = 0.0;
    property.m_J   = (b * tb * tb * tb + a * ta * ta * ta + hf * tw * tw * tw) / 3.0;
    property.m_K1  = tw * hw / property.m_A;
    property.m_K2  = 5.0 * (a * ta + b * tb) / (6.0 * property.m_A);
    property.m_NSM = section.m_nsm;
    property.m_FE  = 0.0;
    property.SetStressPoints ({-yC + hf + 0.5 * tb,  0.5 * b,
                               -yC - 0.5 * ta,       0.5 * a,
                               -yC - 0.5 * ta,      -0.5 * a,
                               -yC + hf + 0.5 * tb, -0.5 * b});
    centroid.m_x = 0.0;
    centroid.m_y = 0.0;
    centroid.m_z = 0.0;
}